/**
 * Bamboo Software Organization
 * Java open source software.  
 */
package org.bamboo.easyejb.demo.client;

import junit.framework.TestCase;

import org.bamboo.easyejb.client.EJBConnection;
import org.bamboo.easyejb.client.EasyEJBConfigUtil;
import org.bamboo.easyejb.demo.weather.model.WeatherInfo;

/**
 * @author Ramond KK He, raymond.kk.he@gmail.com 
 * @version 1.0 
 * 2008-11-27  
 */
public class WeatherReportClientDemo extends TestCase{
	
	public void testRemoteEJB() {			
		//test in jboss4.0.0
		//also can be tested with remote WAS, Weblogic etc.
		EJBConnection ejbConnection = new EJBConnection( EasyEJBConfigUtil.getInitialContextProperties());	
		
		
		Object[] ags = new Object[] {"Beijing"};
		try {
			WeatherInfo weatherInfo = (WeatherInfo)ejbConnection.invokeRemoteLocalEJB("org.bamboo.easyejb.demo.weather.ejb.WetherReport","getWeatherInfo",ags);
			System.out.println("result: weather of Beijing: " + weatherInfo.getWeather() +"," + weatherInfo.getTemperature());
			assertEquals("WeatherInfo result ", "Beijing", ((WeatherInfo)weatherInfo).getCity());
		} catch (Exception e) {
			System.out.println("exception:" + e);
			fail(e.toString());
		}
	}
	/**
	 * throw city not found exception
	 *
	 */
	public void testRemoteEJB2() {		
		//test in jboss4.0.0
		//also can be tested with remote WAS, Weblogic etc.
		EJBConnection ejbConnection =  new EJBConnection( EasyEJBConfigUtil.getInitialContextProperties());	
		
		
		Object[] ags = new Object[] {"Tokyo"};
		try {
			Object s = ejbConnection.invokeRemoteLocalEJB("org.bamboo.easyejb.demo.weather.ejb.WetherReport","getWeatherInfo",ags);
			System.out.println("result " + s);
			fail("CityNotFoundException should be thrown!");
		} catch (Exception e) {
			System.out.println("exception:" + e);
			assertNotNull(e);
		}
	}
	
	public static void main(String[] args) {	
		//TestRunner.run(WeatherReportClientDemo.class);
		
		WeatherReportClientDemo clientDemo = new WeatherReportClientDemo();
		clientDemo.testRemoteEJB();
	}
}
